package com.baizhi.service.impl;

import com.baizhi.dao.BrandDao;
import com.baizhi.entity.Brand;
import com.baizhi.service.BrandService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class BrandServiceImpl implements BrandService {
    @Autowired
    private BrandDao brandDao;
    @Override
    public void insert(Brand brand) {
        brandDao.insert(brand);
    }

    @Override
    public void delete(Integer id) {
        brandDao.delete(id);
    }

    @Override
    @Transactional(readOnly = true)
    public Brand selectById(Integer id) {
        return brandDao.selectById(id);
    }

    @Override
    public void update(Brand brand) {
        brandDao.update(brand);
    }

    @Override
    @Transactional(readOnly = true)
    public PageInfo<Brand> selectByPage(String name, Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        PageInfo<Brand> pageInfo = new PageInfo<>(brandDao.selectByName(name));
        return pageInfo;
    }
}
